package com.infore.qualityControl.export.policy.strategy.concreteStrategy;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.infore.qualityControl.export.policy.bo.ExportParamBo;
import com.infore.qualityControl.export.policy.strategy.Strategy;
import com.infore.qualityControl.export.util.ExportUtil;
import com.infore.qualityControl.remoteEntity.EquipmentInfo;
import com.infore.qualityControl.remoteService.IDataReceivingService;
import com.infore.qualityControl.util.MyBeanUtils;
import com.infore.qualityControl.util.ObjectMapperUtil;
import com.infore.qualityControl.util.ResultEntity;

@Service("LOG_STATUS_DATA")
public class LogStatusStrategy implements Strategy {
    
    @Autowired
    IDataReceivingService IDataReceivingService;
    
    @Autowired
    ObjectMapperUtil ObjectMapperUtil;

    @Override
    public byte[] doExcelStrategy(List<Map<String, Object>> list, ExportParamBo exportParamBo) throws Exception {
		list = this.doData(list, exportParamBo);
		return ExportUtil.exportExcel(exportParamBo.getRequest(), list, exportParamBo.getHeaderProp(), exportParamBo.getPattern());
    }

    @Override
    public byte[] doPdfStrategy(List<Map<String, Object>> list, ExportParamBo exportParamBo) throws Exception {
        list = this.doData(list, exportParamBo);
        return ExportUtil.exportPdf(exportParamBo.getRequest(), list, exportParamBo.getHeaderProp(), exportParamBo.getPattern());
    }

    @Override
    public byte[] doWordStrategy(List<Map<String, Object>> list, ExportParamBo exportParamBo) throws Exception {
        list = this.doData(list, exportParamBo);
        return ExportUtil.exportWord(exportParamBo.getRequest(), list, exportParamBo.getHeaderProp(), exportParamBo.getPattern());
    }

    @Override
    public List<Map<String, Object>> doData(List<Map<String, Object>> list, ExportParamBo exportParamBo) throws Exception {
        ResultEntity resultEntity = IDataReceivingService.queryLogStatusData(exportParamBo.getStationCodes(), exportParamBo.getStartTime(),
                exportParamBo.getEndTime(), exportParamBo.getLogType(), null, null);
        List<EquipmentInfo> equipmentInfoList = ObjectMapperUtil.convertList(resultEntity, EquipmentInfo.class);
        for (EquipmentInfo equipmentInfo : equipmentInfoList) {
            list.add(MyBeanUtils.convertBeanToMap(equipmentInfo, exportParamBo.getPattern()));
        }
        return list;
    }

}
